<template>
	<view>
		<baseForm :column.sync="column" @submitFun="submitFun" :submitStatus="submitDisable" :button="button"></baseForm>
		<progressBox :auditVos="auditVos" dictcode="dict_audit_status"></progressBox>
		<view class="buttons" v-if="getApprovalShow('applyStatus')">
			<button size="mini" class="middleButton" @click="pass('教师请假', itemData)">通过</button>
			<button size="mini" class="middleButton" @click="unpass('教师请假', itemData)">不通过</button>
		</view>
	</view>
</template>

<script>
import baseForm from '@/wxcomponents/form/form.vue';
import pickerModule from '@/wxcomponents/form/picker.vue';
import { format, dectList,dictCode } from '@/libs/common.js';
import common from '@/libs/login.js';
import progressBox from '@/wxcomponents/commonLayout/progressLevel.vue';
import userMixins from '@/libs/userMixins.js'
import approvalMixins from '@/libs/approvalMixins.js'
import formMixins from '@/libs/formMixins.js'
export default {
	mixins: [userMixins, approvalMixins, formMixins],
	data() {
		let self = this;
		return {
			itemData: '',
			column: [
				{
					label: '请假类型',
					name: 'leaveType',
					type: 'picker',
					required: true,
					disabled: true,
					value: '',
					text: '请选择请假类型',
					mode: 'selector', //picker的类型
					range: self.findOneDictList('dict_leave_type')
				},
				{
					label: '请假原因', 
					name: 'leaveReason',
					type: 'picker',
					required: true,
					disabled: true,
					value: '',
					text: '请选择请假原因',
					mode: 'selector', //picker的类型
					range: self.findOneDictList('dict_leave_reason')
				},
				{
					label: '请假详情',
					name: 'reasonDetail',
					type: 'normalInput',
					required: false,
					disabled: true,
					value: '',
					text: '',
				},
				{
					label: '起始时间',
					value: format('YY-mm-dd', new Date()),
					required: true,
					disabled: true,
					name: 'startTime',
					type: 'picker',
					mode: 'date',
					text: format('YY-mm-dd', new Date())
				},
				{
					label: '结束时间',
					value: format('YY-mm-dd', new Date()),
					required: true,
					disabled: true,
					name: 'endTime',
					type: 'picker',
					mode: 'date',
					text: format('YY-mm-dd', new Date())
				},
				{
					label: '附件(最多上传三张)',
					type: 'upload',
					url: '/stu/common/uploadFile',
					attachmentVoListStr: '',
					limitSize:3,
					disabled:true
				}
			],
			button: {
				hide: true
			},
			progressInfo: [
				{
					name: '审批通过',
					value: 2
				},
				{
					name: '审批中',
					value: 1
				},
				{
					name: '已提交',
					value: 0
				}
			],
			status: 1,
			auditVos: ''
		};
	},
	async onLoad(option) {
		this.itemData = JSON.parse(option.data);
		this.getDetail(this.itemData.id);
	},
	methods: {
		async getDetail(id) {
			let self = this;
			let caseMap = [
				{
					condition() {	// 详情
						return self.itemData.detailType == 'detail'
					},
					async func() {
						let resp = await self.$http.get({
							url: `/oa/leaveApply/detail?id=${id}`
						});
						self.assignFormDataToViewModel(resp.result, self.column);
						self.auditVos = resp.result.auditList;
					}
				},
				{
					condition() {	// 审批
						return self.itemData.detailType == 'approval'
					},
					async func() {
						let resp = await self.$http.get({
							url: `/oa/leave/detail?id=${id}`
						});
						self.assignFormDataToViewModel(resp.result, self.column);
						self.auditVos = resp.result.auditList;
					}
				},
			]
			let findOne = caseMap.filter(item => {
				return item.condition()
			})[0]
			if (!findOne) {
				alert(`getDetail方法出错`)
			}
			findOne.func();
		},
		calDetailReasonShowStatus(leaveReasonName) {
			this.column[2].hidden = leaveReasonName != '其他';
		},
	
	},
	components: {
		baseForm,
		pickerModule,
		progressBox
	},
	computed: {
		leaveReasonName() {
			let column = this.column[1];
			return column.text
		}
	},
	watch: {
		leaveReasonName: {
			handler: function(leaveReasonName) {
				this.calDetailReasonShowStatus(leaveReasonName)
			},
			deep: true
		}
	}
};
</script>

<style></style>
